package cn.practice.chat.feign.api;

import cn.practice.chat.entity.UserPassword;
import cn.practice.chat.feign.service.UserPasswordFeign;
import cn.practice.chat.lang.Result;
import cn.practice.chat.response.user.UserPasswordResult;
import cn.practice.chat.service.UserPasswordService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName UserPasswordFeignImpl
 * @Description:
 * @Author A-TAO
 * @Date 2022/10/31
 * @Version V1.0
 **/
@Slf4j
@RestController
public class UserPasswordFeignImpl implements UserPasswordFeign {

    @Autowired
    private UserPasswordService userPasswordService;


    @Override
    public Result<UserPasswordResult> getUserDetail(String username) {
        log.info("UserPasswordFeign 查询账户信息，username={}", username);
        UserPasswordResult result = null;

        LambdaQueryWrapper<UserPassword> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserPassword::getUsername , username);

        UserPassword userPassword = userPasswordService.getOne(queryWrapper);
        log.info("UserPasswordFeign 查询账户信息，result={}", userPassword);
        if(userPassword != null){
            result = new UserPasswordResult();
            BeanUtils.copyProperties(userPassword, result);
        }
        return Result.success(result);
    }


}
